﻿#region Header
// Copyright 2007-2011, Jerónimo Milea
// 
// This file is part of NetJsWire.
// 
//     NetJsWire is free software: you can redistribute it and/or modify
//     it under the terms of the GNU General Public License as published by
//     the Free Software Foundation, either version 3 of the License, or
//     (at your option) any later version.
// 
//     NetJsWire is distributed in the hope that it will be useful,
//     but WITHOUT ANY WARRANTY; without even the implied warranty of
//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//     GNU General Public License for more details.
// 
//     You should have received a copy of the GNU General Public License
//     along with NetJsWire.  If not, see <http://www.gnu.org/licenses/>.
#endregion

using System.ComponentModel;
using Newtonsoft.Json;

namespace NetJsWire.Lite.Widgets.UI.Data
{
    public class GroupingStore : Store
    {
        ///<summary>
        ///  Initializes a new instance of GroupingStore.
        ///</summary>
        public GroupingStore()
            : this( null )
        {
        }

        ///<summary>
        ///  Initializes a new instance of GroupingStore and adds it to the Container.
        ///</summary>
        ///<param name = "container"></param>
        public GroupingStore( IContainer container )
            : base( container )
        {
            Xtype = "groupingstore";
            GroupDir = "ASC";
        }

        [JsonProperty( "groupDir", NullValueHandling = NullValueHandling.Ignore, DefaultValueHandling = DefaultValueHandling.Ignore )]
        [DefaultValue( "ASC" )]
        [Browsable( true )]
        [Description( "The direction to sort the groups. Defaults to 'ASC'." )]
        public string GroupDir { get; set; }

        [JsonProperty( "groupField", NullValueHandling = NullValueHandling.Ignore, DefaultValueHandling = DefaultValueHandling.Ignore )]
        [DefaultValue( ( string ) null )]
        [Browsable( true )]
        [Description( "The field name by which to sort the store's data (defaults to '')." )]
        public string GroupField { get; set; }

        [JsonProperty( "groupOnSort", DefaultValueHandling = DefaultValueHandling.Ignore )]
        [DefaultValue( false )]
        [Browsable( true )]
        [Description( "True to sort the data on the grouping field when a grouping operation occurs, false to sort based on the existing sort info (defaults to false)." )]
        public bool GroupOnSort { get; set; }

        [JsonProperty( "remoteGroup", DefaultValueHandling = DefaultValueHandling.Ignore )]
        [DefaultValue( false )]
        [Browsable( true )]
        [Description( "True if the grouping should apply on the server side, false if it is local only (defaults to false). If the grouping is local, it can be applied immediately to the data. If it is remote, then it will simply act as a helper, automatically sending the grouping field name as the 'groupBy' param with each XHR call." )]
        public bool RemoteGroup { get; set; }
    }
}
